package com.xxzb.pack0720;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Scanner;

public class Test8 {
    public static void main(String[] args) throws  Exception{
        Scanner sc=new Scanner(System.in);
        System.out.println("请您输入最小年龄：");
        int minage = sc.nextInt();
        System.out.println("请您输入最大年龄：");
        int maxage = sc.nextInt();
        Class.forName("com.mysql.jdbc.Driver");
        String url ="jdbc:mysql:///gaofeng2207?useSSL=false";
        String username="root";
        String password="1234";
        Connection conn= DriverManager.getConnection(url,username,password);
        String sql="select * from gaofeng2207.readers where readerAge between ? and ?";
        PreparedStatement ps=conn.prepareStatement(sql);
        ps.setInt(1,minage);
        ps.setInt(2,maxage);
        ResultSet rs = ps.executeQuery();
        while (rs.next()){
            int readerId=rs.getInt(1);
            String readerName=rs.getString(2);
            String readerSex=rs.getString(3);
            int readerAge=rs.getInt(4);
            int rederPhone=rs.getInt(5);
            System.out.print(readerId+"\t");
            System.out.print(readerName+"\t");
            System.out.print(readerSex+"\t");
            System.out.print(readerAge+"\t");
            System.out.print(rederPhone+"\n");
        }
        


    }
}
